<?php

namespace App\Department\Controllers;

use App\Http\Controllers\Controller;
use App\Services\TransverseService;
use App\Transverse;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class TransverseTjController extends Controller
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '横向课题统计';
    protected $service;

    public function __construct(TransverseService $service)
    {
        $this->service = $service;
    }

    public function index(Content $content)
    {
        return $content
            ->title($this->title)
            ->description(trans('admin.list'))
            ->body($this->grid());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Transverse());
        $grid->model()->where('department_id',Admin::user()->department_id);
        $this->service->gridColumn($grid);
        $grid->batchActions(function(Grid\Tools\BatchActions $actions){
            $actions->disableDeleteAndHodeSelectAll();
        });
        $grid->disableActions();
        $grid->disableCreateButton();
        return $grid;
    }
}
